package com.ss.android.article.base.ui;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.View;
import android.view.WindowManager;

import com.bytedance.common.utility.UIUtils;
import com.ss.android.article.browser.R;

public class TagView extends View {
    private Paint a;
    private Paint b;
    private String c;
    private Resources d;
    private RectF e;
    private float f;
    private float g;
    private float h;
    private float i;
    private float j;
    private float k;
    private float l;
    private float m;
    private float n;
    private int o;
    private int p;
    private int q;
    private int r;
    private int s;
    private int t;
    private int u;
    private int v;
    private int w;
    private float x;
    private int y;
    private RectF z;

    public TagView(Context arg2, AttributeSet arg3) {
        this(arg2, arg3, 0);
    }

    public TagView(Context arg5, AttributeSet arg6, int arg7) {
        super(arg5, arg6, arg7);
        this.c = "";
        this.f = 0f;
        this.g = 0f;
        this.h = 0f;
        this.i = 0f;
        this.j = 0f;
        this.k = 0f;
        this.l = 0f;
        this.m = 0f;
        this.n = 0f;
        this.o = R.color.ar;
        this.p = R.color.ssxinzi7;
        this.q = R.color.ssxinzi12;
        this.r = R.color.ad;
        this.u = -2147483648;
        this.v = 0;
        this.w = 0;
        this.z = new RectF();
        this.d = arg5.getResources();
        DisplayMetrics v1 = new DisplayMetrics();
        this.a = new Paint();
        this.b = new Paint();
        this.a.setAntiAlias(true);
        this.b.setAntiAlias(true);
        ((WindowManager) arg5.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(v1);
        float v0 = TypedValue.applyDimension(2, 10f, v1);
        this.i = TypedValue.applyDimension(1, 14f, v1);
        this.j = TypedValue.applyDimension(1, 20f, v1);
        this.k = TypedValue.applyDimension(1, 24f, v1);
        this.l = TypedValue.applyDimension(1, 30f, v1);
        this.setTagType(3);
        this.x = v0;
        this.b.setTextSize(this.x);
        this.b.setStrokeWidth(4f);
        this.b.setTextAlign(Paint.Align.CENTER);
        this.b();
    }

    public final void a() {
        int v0;
        int v1 = -2147483648;
        switch (this.t) {
            case -1: {
                v0 = this.u == v1 ? this.d.getColor(this.o) : this.u;
                this.v = v0;
                this.w = this.d.getColor(this.q);
                break;
            }
            case 3: {
                v0 = this.u == v1 ? this.d.getColor(this.o) : this.u;
                this.v = v0;
                this.w = this.d.getColor(this.p);
                break;
            }
            case 4: {
                v0 = this.u == v1 ? this.d.getColor(com.ss.android.article.browser.R.color.ssxinmian4) : this.u;
                this.v = v0;
                this.w = this.d.getColor(com.ss.android.article.browser.R.color.ssxinzi4);
                break;
            }
        }

        this.s = this.d.getColor(this.r);
        this.a.setColor(this.v);
        this.b.setColor(this.w);
        this.invalidate();
    }

    private void b() {
        float v6 = 2f;
        if (!TextUtils.isEmpty(this.c)) {
            boolean v0 = Character.isDigit(this.c.charAt(0));
            int v1 = this.c.length();
            if (v0) {
                switch (v1) {
                    case 1: {
                        this.g = this.i;
                        break;
                    }
                    case 2: {
                        this.g = this.j;
                        break;
                    }
                    default:
                        this.g = this.k;
                        break;
                }
            } else if (v1 == 3) {
                this.g = this.l;
            } else {
                this.g = 0f;
            }

            label_15:
            this.f = this.i;
            this.h = this.f / v6;
            this.e = new RectF(((float) this.y), ((float) this.y), this.g + (((float) this.y)), this.f + (((float) this.y)));
            if (this.t == -1) {
                this.z.set(this.e);
                this.z.inset(((float) (-this.y)), ((float) (-this.y)));
            }

            Paint.FontMetrics v0_1 = this.b.getFontMetrics();
            this.m = (this.g + (((float) (this.y * 2)))) / v6;
            this.n = (this.f + (((float) (this.y * 2)))) / v6 - (v0_1.descent + v0_1.ascent) / v6;
        }
    }

    public float getTagHeight() {
        return this.f + (((float) (this.y * 2)));
    }

    public float getTagWidth() {
        return this.g + (((float) (this.y * 2)));
    }

    protected void onDraw(Canvas arg5) {
        super.onDraw(arg5);
        if (!android.support.design.a.isTextEmpty(this.c)) {
            if (this.t == -1) {
                this.a.setColor(this.s);
                arg5.drawRoundRect(this.z, this.h + (((float) this.y)), this.h + (((float) this.y)), this.a);
                this.a.setColor(this.v);
            }

            arg5.drawRoundRect(this.e, this.h, this.h, this.a);
            arg5.drawText(this.c, this.m, this.n, this.b);
        }
    }

    protected void onMeasure(int arg4, int arg5) {
        if (this.g < 0f || this.f < 0f) {
            super.onMeasure(arg4, arg5);
        } else {
            this.setMeasuredDimension((((int) this.g)) + this.y * 2, (((int) this.f)) + this.y * 2);
        }
    }

    public void setCustomBgColor(int arg1) {
        this.u = arg1;
    }

    public void setDrawText(String arg3) {
        if (arg3 != null && arg3.length() == 3) {
            this.c = arg3;
            this.b();
            this.requestLayout();
            this.a();
        }
    }

    public void setNumber(int arg2) {
        if (arg2 <= 0) {
            this.c = "0";
        } else {
            if (arg2 > 0 && arg2 < 100) {
                this.c = String.valueOf(arg2);
//                goto label_3;
            }else {
                this.c = "99+";
            }
        }

        label_3:
        this.b();
        this.requestLayout();
        this.a();
    }

    public void setTagType(int arg3) {
        int v1 = -2147483648;
        int v0 = arg3 == 3 || arg3 == 4 || arg3 == -1 ? 1 : 0;
        if (v0 != 0) {
            this.t = arg3;
            switch (arg3) {
                case -1: {
                    v0 = this.u == v1 ? this.d.getColor(this.o) : this.u;
                    this.v = v0;
                    this.w = this.d.getColor(this.q);
                    this.s = this.d.getColor(this.r);
                    this.y = ((int) UIUtils.dp2px(this.getContext(), 1f));
                    break;
                }
                case 3: {
                    v0 = this.u == v1 ? this.d.getColor(this.o) : this.u;
                    this.v = v0;
                    this.w = this.d.getColor(this.p);
                    break;
                }
                case 4: {
                    v0 = this.u == v1 ? this.d.getColor(com.ss.android.article.browser.R.color.ssxinmian4) : this.u;
                    this.v = v0;
                    this.w = this.d.getColor(com.ss.android.article.browser.R.color.ssxinzi4);
                    break;
                }
            }

            this.a.setColor(this.v);
            this.b.setColor(this.w);
        }
    }
}

